package com.pucheng.bracelet.ui.adapter

import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.pucheng.bracelet.R
import com.suke.widget.SwitchButton

class PushAdapter(private val callback: (position: Int, data: PushData) -> Unit,private val mData: MutableList<PushData>) :
    BaseQuickAdapter<PushData, BaseViewHolder>(R.layout.item_list_push, mData) {
    override fun convert(holder: BaseViewHolder, item: PushData) {
        holder.setText(R.id.tv_push_name, item.name)
        when (holder.adapterPosition) {
            0 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_phone)
            1 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_msg)
            2 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_qq)
            3 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_wchat)
            5 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_facebook)
            6 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_twitter)
            7 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_whats)
            8 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_wchat)
            9 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_instagram)
            10 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_skype)
            11 -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_line)
            else -> holder.setImageResource(R.id.iv_icon, R.mipmap.ic_msg_more)
        }
       val sbPush =  holder.getView<SwitchButton>(R.id.sb_push)
        sbPush.isChecked = item.selected
        sbPush.setOnCheckedChangeListener { _, isChecked -> item.selected= isChecked
        callback.invoke(holder.adapterPosition,item)
        }

//            .setImageResource(R.id.iv_bg, item.iconBgId)
    }
}

data class PushData(
    var id: Int = 0,
    val name: String = "",
    val iconId: Int = 0,
    var selected: Boolean = true
)
